package com.google.code.alpaca.example.server.handler;

import net.customware.gwt.dispatch.server.ActionHandler;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.DispatchException;

import com.google.code.alpaca.example.rpc.MessageDeleteAction;
import com.google.code.alpaca.example.rpc.VoidResult;
import com.google.code.alpaca.example.server.MessageRepository;

public class MessageDeleteHandler implements ActionHandler<MessageDeleteAction, VoidResult>{

  private MessageRepository messageRepository = new MessageRepository();

  @Override
  public Class<MessageDeleteAction> getActionType() {
    return MessageDeleteAction.class;
  }

  @Override
  public VoidResult execute(MessageDeleteAction action, ExecutionContext context)
      throws DispatchException {
    messageRepository.deleteById(action.getId());
    return VoidResult.VOID;
  }

  @Override
  public void rollback(MessageDeleteAction action, VoidResult result,
      ExecutionContext context) throws DispatchException {
  }

}
